import java.util.Arrays;

public class MyStack {

    public int[] elem;
    public int usedsize;

    public MyStack(){
        this.elem=new int[10];
    }

    public void push(int val){
        if(isFull()){
            this.elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedsize++]=val;
    }
    public boolean isFull(){
        return usedsize==elem.length;
    }

    public int pop(){
        if (isEmpty()){
            throw new EmptyStackException();
        }
        int val=elem[usedsize-1];
        usedsize--;
        return val;
    }

    //获取栈顶元素 但是不是删除
    public int peek(){
        if (isEmpty()){
            throw new EmptyStackException();
        }
        return elem[usedsize-1];
    }

    public boolean isEmpty(){
        return usedsize==0;
    }
}
